<template>
    <!-- 季度评价-新增 -->
    <div class="e-form">
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <div style="width: 100%" class="form">
                <el-form :model="formData" label-width="150px">
                    <BillTop title="分包商季度评价新增" @cancel="handleClose"></BillTop>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="评价日期：">
                                <el-date-picker
                                    disabledDate
                                    v-model="formData.billDate"
                                    :disabled="
                                        !creditEvaluationTypeTable.isModify
                                    "
                                    type="date"
                                    placeholder="选择日期"
                                    @change="formatDate"
                                    :clearable="false"
                                    :picker-options="limitTime"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同名称：">
                                <el-input
                                    v-model="formData.contractName"
                                    placeholder="请选择"
                                    disabled
                                >
                                    <i
                                        slot="suffix"
                                        class="el-icon-document-copy"
                                        @click="onContract"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="统一社会信用代码：">
                                {{ formData.creditCode }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="分包商名称：">
                                {{ formData.subcontractorName }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="分包商类型：">
                                {{ formData.subcontractorTypeKey }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="主营范围：">
                                {{ formData.mian }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="历史信用等级：">
                                {{ formData.historyEvaluate }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="当前评价结论：">
                                {{ formData.evaluationConclusion }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="合同类型：">
                                {{ formData.contractType }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="评价季度：">
                                {{ formData.evaluateQuarter }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="评价机构：">
                                {{ formData.orgName }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="上级机构：">
                                {{ formData.upOrgName }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="状态:">
                                {{ statusLable(formData.state) }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                style="background: #2e61d7"
                @click="save()"
                >保存</el-button
            >
            <el-button @click="cancel()">取消</el-button>
        </div>
    </div>
</template>

<script>
import { mapMutations } from 'vuex'
import { selectDataClient, showSuccessPop } from '@/utils/common'
import subcontractorRAP from '@/api/OutsourcingartyAdmin/subcontractorAdmin/subcontractorRAP.js'
import { creditEvaluationType } from '@/api/base/outsourcer'
// import call from '@/api/OutsourcingartyAdmin/getAllType.js'
export default {
    data () {
        return {
            dialogVisibleSearch: false,
            selectData: false,
            //表单数据
            formData: {
                billDate: new Date().toLocaleDateString().replaceAll('/', '-'),
                closingDate: '',
                contractAmount: '',
                contractId: '',
                contractName: '',
                contractNo: '',
                contractType: '',
                creditCode: '',
                endDate: '',
                evaluateQuarter: '',
                evaluationConclusion: '',
                historyEvaluate: '',
                id: '',
                isGuarantee: '',
                legalPerson: '',
                mian: '',
                signingDate: '',
                state: 0,
                subcontractorId: '',
                subcontractorName: '',
                subcontractorTypeKey: '',
                subcontractorTypeValue: '',
                upOrgId: '',
                upOrgName: ''
            },

            // //类型列表
            typeList: [],
            orgId: '', //机构id
            orgName: '', //机构名称
            // //奖惩类型列表
            // rewardsOrPunishment: [],
            //合同名称数据
            contractData: [],
            kvKey: '', //外包方名称
            kvValue: '', //外包方值
            creditEvaluationTypeTable: {},
            isSkip: false, //是否跳转
            limitTime: {
                //日期禁用
                disabledDate (time) {
                    return time.getTime() > Date.now() //禁用今天以及以前的日期
                }
            }
        }
    },
    created () {
        let data = JSON.parse(localStorage.getItem('vuex'))
        this.orgId = data.userInfo.orgInfo.orgId
        this.orgName = data.userInfo.orgInfo.orgName
        this.getCreditEvaluationType() //获取评价模板，判断是否允许补录
        // this.getType() //获取外包方类型
    },
    computed: {
        // 判断状态
        statusLable () {
            return param => {
                const state = this.$store.state.outsourcer.equipData.state
                const obj = state.find(x => x.value == param)
                if (obj !== undefined) {
                    return obj.label
                }
            }
        }
    },
    methods: {
        ...mapMutations(['setPopConfirm']),
        //选择合同名称
        open () {
            this.selectData = true
        },
        //保存按钮
        async save () {
            let data = JSON.parse(JSON.stringify(this.formData))
            let datas = await subcontractorRAP.subcontractorEvaluateAdd(data)
            if (datas.code != 200) {
                this.clientPop(
                    'info',
                    '保存成功！是否进行下一步操作？',
                    this.gocallback(datas),
                    null,
                    this.cancelCallBack(datas)
                ) // 如果没有参数，且没有 取消 回调事件，则不用传后面两个参数
            } else {
                showSuccessPop('保存失败')
            }
        },
        // 保存成功继续回调
        gocallback (billid) {
            return () => {
                this.$router.push({
                    path: '/quarterEvaluateEdit',
                    query: { billid }
                })
            }
        },
        // 保存成功，取消回调
        cancelCallBack (billid) {
            return () => {
                this.$router.push({
                    path: '/quarterEvaluate',
                    query: { billid }
                })
            }
        },
        // 合同名称查询
        onContract () {
            // 弹窗选择数据
            selectDataClient({
                SelectServiceToken: '/outer/quarter/evaluate/sub/get/contract', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                InitParamsStr: this.formData.billDate,
                Title: '合同选择'
            }).then(val => {
                //选择的合同赋值
                let data =  this.formData.billDate //保存初始化时间，用于选择合同之后赋值给新数据
                this.formData = val[0]
                this.formData['billDate'] = data //时间赋值
                this.formData.state = '0'
            })
        },
        async getCreditEvaluationType () {
            this.creditEvaluationTypeTable = await creditEvaluationType({
                type: '0'
            }) //获取惩罚列表数据
        },
        //取消按钮
        cancel () {
            this.$router.push('/quarterEvaluate')
        },
        // 处理时间
        formatDate (val) {
            this.formData.billDate = this.formatDateTime(val)
        },
        // 格式化时间
        formatDateTime (inputTime) {
            var date = new Date(inputTime)
            var y = date.getFullYear()
            var m = date.getMonth() + 1
            m = m < 10 ? '0' + m : m
            var d = date.getDate()
            d = d < 10 ? '0' + d : d
            return y + '-' + m + '-' + d
        },
        //日期转换格式
        getTime (dt) {
            var year = dt.getFullYear() //年
            var month = dt.getMonth() + 1 //月
            var date = dt.getDate() //日
            month = month < 10 ? '0' + month : month
            date = date < 10 ? '0' + date : date
            var str = year + '-' + month + '-' + date
            return str
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    margin-bottom: 80px;
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
.e-table {
    background: #fff;
}

.el-tab-pane {
    margin-left: -10px;
}
</style>
